package cn.itsource.cw.controller;

import cn.itsource.cw.entity.TbEmployee;
import cn.itsource.cw.service.employee.EmployeeServiceImpl;
import cn.itsource.cw.vo.PageResult;
import cn.itsource.cw.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeServiceImpl employeeService;


    @PostMapping("/insert")
    public Result insertEmployee(@RequestBody TbEmployee employee) {
        employeeService.insertEmployee(employee);
        return new Result(true);
    }

    @PostMapping("/insertempdept")
    public Result insertEmployeeByDeptName(@RequestBody TbEmployee employee, String deptName) {
        employeeService.insertEmployeeByDeptName(employee, deptName);
        return new Result(true);
    }

    @PostMapping("/update")
    public Result updateEmployee(@RequestBody TbEmployee employee) {
        employeeService.updateEmployee(employee);
        return new Result(true);
    }

    @GetMapping("/findbyid/{id}")
    public TbEmployee findEmployeeById(@PathVariable("id") String id) {
        return employeeService.findEmployeeById(id);
    }

    @PostMapping("/findpage")
    public PageResult<TbEmployee> findPageByParam(@RequestBody TbEmployee param, int pageNum, int pageSize) {
        return employeeService.findPageByParam(param, pageNum, pageSize);
    }
}
